Fix NameError in ZImageOmniPipeline when guidance_scale=0#13527
Open
Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Open
Fix NameError in ZImageOmniPipeline when guidance_scale=0#13527Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Contributor
Author
|
Friendly ping — this PR has been approved. Is there anything else needed before merging? Happy to make any requested changes. |
`ZImageOmniPipeline.__call__` only defines `negative_condition_siglip_embeds`
inside a `if self.do_classifier_free_guidance:` block:
if self.do_classifier_free_guidance:
negative_condition_siglip_embeds = [
[se.clone() for se in batch] for batch in condition_siglip_embeds
]
but later reads the name unconditionally when reshaping:
condition_siglip_embeds = [None if sels == [] else sels + [None] for sels in condition_siglip_embeds]
negative_condition_siglip_embeds = [
None if sels == [] else sels + [None] for sels in negative_condition_siglip_embeds
]
`do_classifier_free_guidance` is defined as `self._guidance_scale > 0`,
so any call with `guidance_scale=0.0` raises `NameError`. This is the
exact configuration the pipeline's own `EXAMPLE_DOC_STRING` uses
(`guidance_scale=0.0` for the Z-Image-Turbo distilled checkpoint),
so running the documented snippet crashes.
The downstream consumption at
condition_siglip_embeds_model_input = condition_siglip_embeds + negative_condition_siglip_embeds
is already guarded by `if apply_cfg:`, so we only need to guard the
reshape step to match. Wrap the negative-branch list comprehension in
the same CFG check, matching the symmetric treatment of
`negative_condition_latents` (which is already only defined when
`do_classifier_free_guidance` is true and used only in the CFG branch
of the denoise loop).
e93f057 to
56a6219
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
ZImageOmniPipeline.__call__definesnegative_condition_siglip_embedsonly inside the CFG guard:https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/z_image/pipeline_z_image_omni.py#L581-L582
but a few lines later reads the same name unconditionally:
https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/z_image/pipeline_z_image_omni.py#L590-L593
Why this is a real bug
do_classifier_free_guidanceisself._guidance_scale > 0(line 342), so any call withguidance_scale=0.0leavesnegative_condition_siglip_embedsunbound →NameError: name 'negative_condition_siglip_embeds' is not defined.This is the exact configuration the pipeline's own
EXAMPLE_DOC_STRINGuses:https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/z_image/pipeline_z_image_omni.py#L51-L58
i.e. running the documented Z-Image-Turbo snippet crashes. The downstream consumption (line 648) is already guarded by
if apply_cfg:, so the negative reshape only needs to fire when CFG is on.Fix
Wrap the negative reshape in the same
do_classifier_free_guidancecheck — matching the symmetric treatment ofnegative_condition_latents, which is only defined and only consumed when CFG is on.Before submitting
Who can review?
@yiyixuxu @sayakpaul